package com.yoomiito.app.adapter.dialog

import android.graphics.drawable.GradientDrawable
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.*
import com.yoomiito.app.model.video.VideoOtherInfo
import com.yoomiito.app.utils.*
import com.yoomiito.app.widget.CouponView
import com.yoomiito.app.widget.RoundImageView
import kotlinx.android.synthetic.main.item_goods_9.view.*

class GoodsListDialogAdapter() :BaseQuickAdapter<VideoOtherInfo.ProductBean,BaseViewHolder>(R.layout.item_goods_9,null){

    override fun convert(helper: BaseViewHolder?, item: VideoOtherInfo.ProductBean?) {
        val itemGoods9 = helper?.getView<LinearLayout>(R.id.itemGoods9)
        val lp = itemGoods9?.layoutParams as androidx.recyclerview.widget.RecyclerView.LayoutParams
        lp.leftMargin = DensityUtil.dp2px(12f)
        lp.rightMargin = DensityUtil.dp2px(12f)
        val goodsPic = helper?.getView<RoundImageView>(R.id.goodsPicIv)
        val goodsTitleTv = helper?.getView<TextView>(R.id.goodsTitleTv)
        val awsrdView = helper?.getView<CouponView>(R.id.awardView)
        val couponView = helper?.getView<CouponView>(R.id.couponView)
        val goodsPriceTv = helper?.getView<TextView>(R.id.goodsPriceTv)
        val buy = helper?.getView<TextView>(R.id.buy)
        val drawable = buy?.background as GradientDrawable
        drawable.cornerRadius = DensityUtil.dp2px(15f).toFloat()
        ImageLoader.getInstance().into(mContext,item?.image,goodsPic)
        goodsTitleTv?.text = item?.title
        goodsTitleTv.text = if (item?.type=="1") SpannableUtils.getIconAndText(item?.title, ResUtil.getDrawable(DataUtils.ivType(item.source))) else item?.title

//        awsrdView?.setText("¥${item?.buyAwardPrice}")
        awsrdView?.visibility = View.GONE
//        awsrdView?.visibility = if (null==item?.buyAwardPrice||item?.buyAwardPrice.isEmptyOr0()) View.INVISIBLE else View.VISIBLE
//        awsrdView?.goodsShowCoupon(item?.buyAwardPrice!!,DataUtils.getGoodsType(item.type))
//        if(item?.yo_money!=0){
//            couponView?.setHeaderText("送")
//            couponView?.setText("${item?.couponPrice}优米")
//        }else{
//            couponView?.setHeaderText("券")
//            couponView?.setText("¥${item?.couponPrice}")
//        }
        couponView?.visibility = View.GONE
//        couponView?.goodsShowCoupon(item?.couponPrice!!,DataUtils.getGoodsType(item.type))
        val priceT = item?.discountPrice?.removeDecimalPoint()
        val oldPriceT = item?.zkFinalPrice?.removeDecimalPoint()
        goodsPriceTv?.text = if (item?.zkFinalPrice==null|| oldPriceT!!.isEmptyOr0() ||  priceT==oldPriceT) "¥${priceT}" else "¥${priceT} ¥${oldPriceT}".goodsPrice(priceT!!)
    }

}